load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_benchmark", "mongo_cc_library")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "type_namespace_placement_gen",
    src = "type_namespace_placement.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/sharding_environment:sharding_types_gen",
    ],
)

idl_generator(
    name = "type_chunk_range_base_gen",
    src = "type_chunk_range_base.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "type_chunk_base_gen",
    src = "type_chunk_base.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/sharding_environment:sharding_types_gen",
    ],
)

idl_generator(
    name = "type_collection_gen",
    src = "type_collection.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:keypattern_gen",
        "//src/mongo/db/global_catalog:type_collection_common_types_gen",
        "//src/mongo/db/versioning_protocol:chunk_version_gen",
        "//src/mongo/s/resharding:type_collection_fields_gen",
    ],
)

idl_generator(
    name = "type_database_gen",
    src = "type_database.idl",
    hdrs = [
        "types_validators.h",
    ],
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/sharding_environment:sharding_types_gen",
    ],
)

idl_generator(
    name = "type_remove_shard_event_gen",
    src = "type_remove_shard_event.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "type_config_version_gen",
    src = "type_config_version.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "type_shard_identity_gen",
    src = "type_shard_identity.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "type_shard_collection_gen",
    src = "type_shard_collection.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:keypattern_gen",
        "//src/mongo/db/global_catalog:type_collection_common_types_gen",
        "//src/mongo/db/versioning_protocol:chunk_version_gen",
        "//src/mongo/s/resharding:type_collection_fields_gen",
    ],
)

idl_generator(
    name = "type_shard_database_gen",
    src = "type_shard_database.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/sharding_environment:sharding_types_gen",
    ],
)

mongo_cc_library(
    name = "type_shard_identity_idl",
    srcs = ["type_shard_identity_gen"],
    deps = [
        "//src/mongo/client:connection_string",
        "//src/mongo/db:server_base",
    ],
)

idl_generator(
    name = "chunk_range_gen",
    src = "chunk_range.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "sharding_catalog_client",
    srcs = [
        "sharding_catalog_client.cpp",
    ],
    deps = [
        "//src/mongo/db:keys_collection_document",
        "//src/mongo/db:server_base",
        "//src/mongo/db/exec/document_value",
    ],
)

mongo_cc_library(
    name = "sharding_catalog_client_impl",
    srcs = [
        "sharding_catalog_client_impl.cpp",
    ],
    deps = [
        ":sharding_catalog_client",
        "//src/mongo/db/pipeline",
        "//src/mongo/db/query/compiler/logical_model/projection:projection_ast",
        "//src/mongo/db/repl:read_concern_args",
        "//src/mongo/db/session:logical_session_id_helpers",
        "//src/mongo/db/storage:duplicate_key_error_info",
        "//src/mongo/executor:network_interface",
        "//src/mongo/s:common_s",
        "//src/mongo/s:grid",
        "//src/mongo/s/client:sharding_client",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_library(
    name = "sharding_catalog_client_mock",
    srcs = [
        "sharding_catalog_client_mock.cpp",
    ],
    deps = [
        ":sharding_catalog_client",
        "//src/mongo/s/client:shard_interface",
    ],
)

idl_generator(
    name = "type_collection_common_types_gen",
    src = "type_collection_common_types.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/timeseries:timeseries_gen",
    ],
)

mongo_cc_benchmark(
    name = "chunk_manager_refresh_bm",
    srcs = [
        "chunk_manager_refresh_bm.cpp",
    ],
    tags = ["sharding_bm"],
    deps = [
        "//src/mongo/db:shard_role_api",
    ],
)
